package cn.maka.web.servlet;

import cn.maka.domain.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/success")
public class SuccessServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        User user = (User) request.getAttribute("user");

        HttpSession session = request.getSession();
        User user1 = (User) session.getAttribute("user");

        if (user != null){
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(user.getUsername()+"登陆成功!");
            response.getWriter().write("<br>");
        }else if (user1 != null){
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write(user1.getUsername()+"登陆成功!");
            response.getWriter().write("<br>");

        }else {
            response.setContentType("text/html;charset=utf-8");
            response.getWriter().write("faillllllllllllllllllllll");
        }

        LastTimeServlet lastTimeServlet = new LastTimeServlet();
        lastTimeServlet.doPost(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request,response);
    }
}
